<?php

namespace app\admin\middleware;

use app\BaseController;
use think\facade\Session;

class CheckLogin extends BaseController
{
    /**
     * 白名单
     * @var string[]
     */
    protected $arrWhite = [
        '/admin/login/index',
    ];

    /**
     * 处理请求
     * @param $request
     * @param $next
     * @return \think\response\Json
     */
    public function handle($request, $next)
    {
        $url = request()->baseUrl();
        $url = strtolower(trim($url, '.html'));
        if (!Session::get('admin_id') && !in_array($url, $this->arrWhite)) {
            return redirect('/admin/login/index');
        }
        return $next($request);
    }
}